package gui.obu.alerts.panels;


import java.text.DecimalFormat;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import com.swtdesigner.SWTResourceManager;

public class ObuFollowingAlertPanelImpl extends AbstractAlertPanelImpl implements ObuFollowingAlertPanel {

	private Label distanceLbl;
	private Label currentSpeedLbl;
	private Label distance;
	private Label currentSpeed;
	private Label message;
	
	public ObuFollowingAlertPanelImpl(Display display, Shell shell) {
		super(display, shell);
		distanceLbl = new Label(shell, SWT.NONE);
		currentSpeedLbl = new Label(shell, SWT.NONE);
		distance = new Label(shell, SWT.NONE);
		currentSpeed = new Label(shell, SWT.NONE);
		message = new Label(shell, SWT.CENTER);
	}

	@Override
	public void open() {
		super.open();
		
		distanceLbl.setBounds(96, 115, 138, 19);
		distanceLbl.setText("Following Distance:");
		distanceLbl.setFont(new Font(display, "Arial", 12, SWT.ITALIC));
		
		currentSpeedLbl.setBounds(96, 140, 112, 19);
		currentSpeedLbl.setText("Current Speed:");
		currentSpeedLbl.setFont(new Font(display, "Arial", 12, SWT.ITALIC));
		
		distance.setBounds(240, 115, 58, 19);
		distance.setFont(new Font(display, "Arial", 12, SWT.ITALIC));
		
		currentSpeed.setBounds(214, 140, 84, 19);
		currentSpeed.setFont(new Font(display, "Arial", 12, SWT.ITALIC));
		
		message.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		message.setBounds(61, 165, 257, 48);
		message.setText("Please slow down to\nincrease your following distance");
		message.setFont(new Font(display, "Arial", 16, SWT.ITALIC));
		
		shell.open();
		shell.layout();
	}

	public void setDistance(String distance) {
		this.distance.setText(distance + " ft");
		this.distance.update();
	}
	
	public void setDistance(Number distance) {
		distance = (Double)distance * 3.28;
		DecimalFormat twoDForm = new DecimalFormat("#.##");
		setDistance(twoDForm.format(distance.doubleValue()));
	}
	
	public void setSpeed(String speed) {
		this.currentSpeed.setText(speed + " mph");
		this.currentSpeed.update();
	}
	
	public void setSpeed(Number speed) {
		setSpeed(speed.toString());
	}
	
	@Override
	public void dispose() {
		super.dispose();
		distanceLbl.dispose();
		currentSpeedLbl.dispose();
		distance.dispose();
		currentSpeed.dispose();
		message.dispose();
	}
}
